const { mongoose, db } = require("../utils/mongoose");

let schema = mongoose.Schema({
  createBy:{type:String,required:true},
  createTime:{type:Date,required:false},
  imageUrl:{type:String,required:false},//图片地址
  name: { type: String, required: true }, //人物名
  overview: { type: Array, required: false }, //人物概述
  chineseName: { type: String, required: false },
  birthDate: { type: String, required: false },
  englishName: { type: String, required: false },
  deathDate: { type: String, required: false },
  alias: { type: Array, required: false }, //别名
  college: { type: Array, required: false }, // 毕业院校
  nationality: { type: String, required: false }, //国籍
  career: { type: String, required: false }, //职业
  nation: { type: String, required: false }, //民族
  represent: { type: Array, required: false }, // 代表作
  birthPlace: { type: String, required: false }, //出生地
  achievement: { type: Array, required: false }, // 主要成就
  evaluation: { type: String, required: false }, //社会评价
});

let Collection = mongoose.model("persons", schema);

//新增
const add = (data) => {
  let model = new Collection(data);
  return model
    .save()
    .then((res) => res)
    .catch((err) => {
      return false;
    });
 
};
//查询
const find = (payload) => {
  return Collection.find(payload)
    .then((res) => res)
    .catch((err) => {
      console.log(err);
      return false;
    });
};
//操作
const update = (query, updated) => {
  return Collection.updateOne(query, updated)
    .then((res) => res)
    .catch((err) => {
      console.log(err);
      return false;
    });
};
module.exports = {
  find,
  add,
  update,
};
